#!/bin/sh
if [ ! -f $1 ]; then 
    echo "Can't find input file:" $1
    exit
fi
shFile=$1
helperFile=$2
shFileName=`basename $shFile`
helperFileName=`basename $helperFile`


workDir=./wd
srcImg=tinfoil.img.src
dstImg=$workDir/msvscheck.img
rdImg=$workDir/initrd.img

imgMountDir=$workDir/fdimg
initrdMountDir=$workDir/rdimg

rm -Rf $workDir 
mkdir -p $workDir $imgMountDir $initrdMountDir
cp $srcImg $dstImg

mount -o loop $dstImg $imgMountDir
gunzip -c $imgMountDir/initrd.gz > $rdImg

mount -o loop $rdImg $initrdMountDir
cp $shFile $initrdMountDir/etc/
cp $helperFileName $initrdMountDir/etc/

echo "clear"                    >> $initrdMountDir/etc/rcS
echo "/bin/sh /etc/"$shFileName >> $initrdMountDir/etc/rcS
echo "while [ 1 ]; do done;"    >> $initrdMountDir/etc/rcS
umount $initrdMountDir

gzip -c $rdImg > $imgMountDir/initrd.gz
umount $imgMountDir

rm -Rf $imgMountDir $initrdMountDir